package org.example.mulitithreading.ex12;

public class Cooker extends Thread {
    @Override
    public void run() {
        while(true){
            synchronized (Desk.lock){
                if(Desk.count == 0){    // 若消费者无法再消费，则生产者退出循环，结束线程
                    break;
                }else{
                    if(Desk.foodFlag == 0){ // 没有食物，生产食物
                        System.out.println("厨师正在生产汉堡包");
                        Desk.foodFlag = 1;
                        Desk.lock.notifyAll();
                    }else{  // 有食物，等待消费者吃完
                        try {
                            Desk.lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}
